﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TheOutfield.UmbExt.PrivateMessaging.Model;

namespace TheOutfield.UmbExt.PrivateMessaging.Data
{
    public class RecipientRepository
    {
        protected Connection conn;

        public RecipientRepository()
        {
            conn = new Connection();
        }

        public Recipient CreateRecipient(Recipient recipient)
        {
            using (var dc = conn.GetContext())
            {
                dc.Recipients.InsertOnSubmit(recipient);
                dc.SubmitChanges();
            }

            return recipient;
        }

        public Recipient UpdateRecipient(Recipient recipient)
        {
            using (var dc = conn.GetContext())
            {
                dc.Recipients.Attach(recipient, true);
                dc.SubmitChanges();
            }

            return recipient;
        }
    }
}